package main.java.indi.zyj.coderecord;

import main.java.indi.zyj.hot100.base.ListNode;

public class _05_removeElements {
    public ListNode removeElements(ListNode head, int val) {
        while (head.val == val) {
            head = head.next;
        }
        if (head == null){
            return head;
        }
        ListNode pre = head, cur = head.next;
        while (cur != null) {
            if (cur.val == val) {
                pre.next = cur.next;
            } else {
                pre = cur;
            }
            cur = cur.next;
        }
        return head;
    }
}
